package lacus.wd_cinema.repository;

import lacus.wd_cinema.entity.Movie;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

/**
 * 与电影相关的数据访问类
 */
@Repository
public interface MovieRepository extends CrudRepository<Movie, Long> {
    Page<Movie> findAll(Pageable pageable);

    @Query("SELECT u FROM Movie u WHERE CAST(u.id AS string) LIKE %:keyword%")
    Page<Movie> findByIdContaining(String id, Pageable pageable);

    Page<Movie> findByTitleContaining(String searchItem, Pageable pageable);

    Page<Movie> findByDirectorContaining(String searchItem, Pageable pageable);

    Page<Movie> findByStarringContaining(String searchItem, Pageable pageable);

    Page<Movie> findByDescriptionContaining(String searchItem, Pageable pageable);

}
